<template>
  <div>
    <FilterTable
      ref="table"
      height="auto"
      :columns="columns"
      columnsRef="partPartPurchasePurchasePlaneDetailModal"
      :dataSource="list"
      :isMemoryPagination="true"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <!-- <el-button size="small" icon="iconfont icon-daochu">导出</el-button>
        <el-button size="small" icon="iconfont icon-dayin">打印</el-button>-->
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { queryBillPartDetailById } from '@/api/part/partPurchase/purchasePlane';

import { dictionary } from '@/utils/dictMixin';

export default {
  mixins: [dictionary],
  props: {
    billNo: String
  },
  data() {
    return {
      columns: this.createTableColumns(),
      list: []
    };
  },
  mounted() {
    if (this.billNo) {
      this.queryPartList();
    }
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 200,
          showOverflowTooltip: true
        },
        {
          title: '计划数量',
          dataIndex: 'nForecast',
          summation: true,
          summationUnit: '',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '库存数量',
          dataIndex: 'stockQuantity',
          summation: true,
          summationUnit: '',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '可用数量',
          dataIndex: 'useableQuantity',
          summation: true,
          summationUnit: '',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '含税采购单价',
          dataIndex: 'planPrice',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '含税采购金额',
          dataIndex: 'total_planPrice',
          summation: true,
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '需求日期',
          dataIndex: 'dDemand',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        }
        // {
        //   title: '厂家配件代码',
        //   dataIndex: 'a10',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // }
      ];
    },
    async queryPartList() {
      this.$refs.table.START_LOADING();
      let res = await queryBillPartDetailById({
        vBillNo: this.billNo
      });
      this.$refs.table.STOP_LOADING();
      res.data.map(item => {
        item.total_planPrice = item.planPrice * item.nForecast;
      });
      this.list = this.list.concat(res.data);
    }
  }
};
</script>

<style lang="less" scoped></style>
